<?php

import("data.db.DbAbstractTable");
import("data.db.DbFactory");
import("data.logic.lingvo.Lingvo");

class DbLingvo extends DbAbstractTable {
	
	public $className = "data.logic.lingvo.Lingvo";
	const CLASS_NAME = "data.logic.lingvo.Lingvo";
	
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_lingvo";
	const TB_I			= 'sprop';
	
	const TB_VALUE		= 'sprop_value';
	const TB_CLEAR_VALUE= 'sprop_clear_value';
	const TB_CLEAR_KEY	= 'sprop_clear_key';
	const TB_LANG		= 'sprop_lang';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_key";}
	public static function _get_SUFFIX() {return self::TB_I;}
	//
	//
	
	// properties
	public $value;
	public $clear_value;
	public $clear_key;
	public $language;
	
	public function __construct($noinit=false) {
		parent::__construct($noinit);
	}
	
	function setLanguage($lang) {
		$this->language = $lang;
	}
	
	function getLanguage() {
		return $this->language;
	}
	
	function getValue() {
		return $this->value;
	}
	
	function setValue($value) {
		$this->value = $value;
	}
	
	function getClearValue() {
		if (isset($this->clear_value)) return $this->clear_value;
		return $this->value;
	}
	
	function setClearValue($value) {
		$this->clear_value = $value;
	}
	
	function getClearKey() {
		return $this->clear_key;
	}
	
	function setClearKey($value) {
		$this->clear_key = $value;
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setValue($arrResult[self::TB_VALUE]);
		$this->setClearKey($arrResult[self::TB_CLEAR_KEY]);
		$this->setClearValue($arrResult[self::TB_CLEAR_VALUE]);
		$this->setLanguage($arrResult[self::TB_LANG]);
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_VALUE] = "'".$this->getValue()."'";
		$this->fildsForStore[self::TB_CLEAR_KEY] = "'".$this->getClearKey()."'";
		$this->fildsForStore[self::TB_CLEAR_VALUE] = "'".$this->getClearValue()."'";
		$this->fildsForStore[self::TB_LANG] = "'".$this->getLanguage()."'";
	}
	
	public static function getAllByLang($lang_id=null) {
		if ($lang_id) {
			return parent::__selectByCriteria(DbLingvo::TB_LANG."='$lang_id'",'data.logic.lingvo.Lingvo');
		} else {
			return self::findAll();
		}
	}
	
	public static function findByKey($key, $lang) {
		return parent::__selectByCriteria(
			self::_get_ID()."='".$key."' and ".self::TB_LANG."='".$lang."'", self::CLASS_NAME);
	}
	
	// same for all classes
    public static function findAll() {return parent::findAll(self::CLASS_NAME);}
    public static function findById($id) {return parent::findById($id, self::CLASS_NAME);}
}
?>